package com.ebupt.migu.music.userGroup.controller;


import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.common.util.ReqestParamUtil;
import com.ebupt.migu.music.userGroup.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by Intellij IDEA.
 * User:  liuyangyang@cd.ebupt.com
 * Date:  2019/9/10
 */
@RestController
@RequestMapping("/file")
public class FileUploadController {

    @Autowired
    private HttpServletRequest request;
    @Autowired
    private FileUploadService fileUploadService;
    @Resource
    private ReqestParamUtil reqestParamUtil;

    /**
     * 文件上传
     * @param file
     * @return
     */
    @PostMapping(value = "/upload")
    public ResultObject uploadCSVFile(@RequestParam("file") MultipartFile file) {
        return fileUploadService.uploadCSVFile(file);
    }

    /**
     * 删除文件
     * @return
     */
    @PostMapping(value = "/delete")
    public ResultObject deleteCSVFile(){
        Map<String, Object> params = reqestParamUtil.getParams2(request);
        return fileUploadService.deleteCSVFile(params);
    }

    /**
     * 创建用户群
     * @return
     */
    @PostMapping(value = "/create")
    public ResultObject createUserGroup(){
        Map<String, Object> params = reqestParamUtil.getParams2(request);
        return fileUploadService.createUserGroup(params);
    }

    /**
     * 创建重度用户群
     * @return
     */
    @PostMapping(value = "/createValue")
    public ResultObject createValueUserGroup(){
        Map<String, Object> params = reqestParamUtil.getParams2(request);
        return fileUploadService.createValueUserGroup(params);
    }

    /**
     * 创建用户实时人群
     * @return
     */
    @PostMapping("/createUserLifeCycle")
    public ResultObject<String> createUserLifeCycle() {
        Map<String, Object> params = reqestParamUtil.getParams2(request);
        return fileUploadService.createUserLifeCycle(params);
    }

}
